<?php

namespace app\admin\model;

use app\lib\Qiniu;

class Memberlevel extends Base
{

    // 数据表名称
    //protected $table;

    // 当前模型名称 不带前缀
    protected $name = 'member_level';

    // 数据表主键 复合主键使用数组定义 不设置则自动获取
    protected $pk = 'id';


    public static function _after_delete($id){
        if(is_array($id)){
            $list = Image::where('related_table', 'member_level')->whereIn('related_id', $id)->select();
        }else{
            $list = Image::where('related_table', 'member_level')->where('related_id', $id)->select();
        }

        $Qiniu = new Qiniu();
        foreach ((array)$list as $item) {
            $key = substr(strrchr($item['img_url'], '/'), 1);
            // 删除七牛图片
            $res = $Qiniu->delImg($key);

            Image::where('id', $item['id'])->delete();
        }
    }
}